import matplotlib.pyplot as plt


def savePic(yline, path):

    plt.rcParams["font.sans-serif"] = ["SimHei"]  # 设置字体
    plt.rcParams["axes.unicode_minus"] = False  # 正常显示负号

    data = {'0~50': 0, '50~100': 0, '100~150': 0, '150~200': 0, '200~250': 0, '250~300': 0, '300~350': 0, '350~400': 0,
            '400~450': 0, '450~500': 0, '500~550': 0, '550~600': 0}
    for i in yline:
        if i > 0 and i <= 50 * 1:
            data['0~50'] = data['0~50'] + 1
        if i > 50 * 1 and i <= 50 * 2:
            data['50~100'] = data['50~100'] + 1
        if i > 50 * 2 and i <= 50 * 3:
            data['100~150'] = data['100~150'] + 1
        if i > 50 * 3 and i <= 50 * 4:
            data['150~200'] = data['150~200'] + 1
        if i > 50 * 4 and i <= 50 * 5:
            data['200~250'] = data['200~250'] + 1
        if i > 50 * 5 and i <= 50 * 6:
            data['250~300'] = data['250~300'] + 1
        if i > 50 * 6 and i <= 50 * 7:
            data['300~350'] = data['300~350'] + 1
        if i > 50 * 7 and i <= 50 * 8:
            data['350~400'] = data['350~400'] + 1
        if i > 50 * 8 and i <= 50 * 9:
            data['400~450'] = data['400~450'] + 1
        if i > 50 * 9 and i <= 50 * 10:
            data['450~500'] = data['450~500'] + 1
        if i > 50 * 10 and i <= 50 * 11:
            data['500~550'] = data['500~550'] + 1
        if i > 50 * 11 and i <= 50 * 12:
            data['550~600'] = data['550~600'] + 1


    name = list(data.keys())
    value = list(data.values())
    plt.figure(figsize=(14,9))
    plt.title('颗粒污泥粒径分布情况', fontsize=25, pad=20)
    plt.xticks(fontsize=15)
    plt.yticks(fontsize=15)
    plt.xlabel('颗粒污泥粒径所在区间 - 单位/um',fontsize=25,labelpad=15)
    plt.ylabel('该区间颗粒污泥个数 - 单位/个',fontsize=25,labelpad=15)
    plt.bar(name, value, width=0.8)
    plt.savefig(path)
